package FTPListing::Unix;

# $Id: Unix.pm 128 2010-06-26 14:45:45Z dolbanavt $
# $Date: 2010-06-26 17:45:49 +0300 (Суб, 26 Июн 2010) $
# $HeadURL: https://robosearch.googlecode.com/svn/branches/reborn/lib/FTPListing/Unix.pm $
# $LastChangedRevision: 345 $

use parent qw( FTPListing );
use JIP::ToolSet;
use English qw( -no_match_vars );
use Const::Fast qw( const );

our $VERSION = '1.0';

const my $REGEX => qr{
    ^([d-])[a-z-]{9}      # drwxr-xr-x
    \s+\d*                # 1
    (?:\s+\w+){2}         # ftp ftp
    \s+(\d+)              # 0
    \s+\w+\s+\d+\s+[\d:]+ # Feb 15 17:34
    \s+(.+)$              # linux_format
}xms;

sub parse_listing_for {
    shift; # shift @ARG;

    my @listing;

    foreach ( @ARG ) {
        if ( my( $type, $size, $name ) = $ARG =~ $REGEX ) {
            if ( $type eq '-' ) {
                $type = 'f'
            }
            elsif ( $type eq 'd' ) {
                $size = undef;

                next if $name eq '.' or $name eq '..';
            }

            push @listing, {
                name => $name,
                type => $type,
                size => $size,
            };
        }
    }

    return @listing;
}

1;

__END__

=head1 NAME

FTPListing::Unix - класс для парсингов листингов Net::FTP::dir()
в формате Unix

=head1 SYNOPSIS

    use FTPListing::Unix;

    my $t = FTPListing::Unix->new();

=head1 DESCRIPTION

=head1 DEPENDENCIES

Const::Fast (from CPAN)

JIP::ToolSet (from base_lib)

=head1 AUTHOR

Vladimir Zhavoronkov, <dolbanavt (at) Google Mail>

http://dolbanavt.livejournal.com/

=head1 LICENSE AND COPYRIGHT

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

=cut
